// let Person = (function () {
//     let instance = null
//     return function (name, age) {
//         this.name = name
//         this.age = age
//         if(instance){
//             return instance
//         }
//         return instance = this
//     }
// })()
// // function Person(name, age) {
// //     this.name = name;
// //     this.age = age
// // }

// let jitao = new Person('计涛', 20)
// let yc = new Person('严辰', 21)

// console.log(jitao);
// console.log(yc);
// console.log(jitao===yc);

function Person(name, age) {
    this.name = name;
    this.age = age
}

Person.prototype.sayHello = function () {
    console.log(this.name)
}

let personProxy = (function () {
    let instance = null
    return function (name,age) {
        if (instance) {
            return instance
        }
        return instance = new Person(name, age)
    }
})()

let jitao = new personProxy('计涛', 20)
let yc = new personProxy('严辰', 21)

console.log(jitao)
console.log(yc)
console.log(jitao === yc)
jitao.sayHello();
yc.sayHello();
